﻿using SWBetongXaydung.GUI.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SWBetongXaydung.GUI.HeThong
{
    public partial class FormDangNhap : BaseDialog
    {
        private DAL.NguoiSuDung m_NguoiSuDung = null;
        public DAL.NguoiSuDung NguoiSuDung
        {
            get { return m_NguoiSuDung; }
            private set { m_NguoiSuDung = value; }
        }

        public FormDangNhap()
        {
            InitializeComponent();
        }

        private void btnDongY_Click(object sender, EventArgs e)
        {
            var tenDangNhap = txtTenDangNhap.Text;
            var matKhau = txtMatKhau.Text;

            this.NguoiSuDung = BLL.HeThong.GetNguoiSuDung(tenDangNhap, matKhau);
            if (this.NguoiSuDung != null)
            {
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            else
            {
                Utils.DialogUtils.ShowMessage("Thông tin đăng nhập không hợp lệ");

                txtMatKhau.Clear();
                txtTenDangNhap.Focus();
            }
        }

        private void txtMatKhau_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
                btnDongY.PerformClick();
        }

        private void FormDangNhap_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control && e.Alt && e.Shift && e.KeyCode == Keys.F12)
            {
                var frm = new HeThong.FormThietLapChuoiKetNoi()
                {
                    StartPosition = FormStartPosition.CenterScreen,
                    TopMost = true
                };
                frm.ShowDialog();
                frm.Dispose();
                frm = null;
            }
        }
    }
}
